package cn.mumzone.pos.ui.adapter;

import android.content.Context;
import android.text.TextUtils;

import java.util.List;

import cn.mumzone.basic.adapter.rv.CommonAdapter;
import cn.mumzone.basic.adapter.rv.ViewHolder;
import cn.mumzone.basic.util.ListUtil;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.ReturnGoodsEntity;

/**
 * Created by JoeLjt on 2019/7/9.
 * Email: lijiateng1219@gmail.com
 * Description:
 * 退货流程第二步，确认退货商品的 adapter
 */

public class ADA_BillReturnCartStepTwo extends CommonAdapter<ReturnGoodsEntity> {

    public ADA_BillReturnCartStepTwo(Context context) {
        super(context);
    }

    @Override
    protected int itemLayoutId() {
        return R.layout.item_return_cart_step_two;
    }

    @Override
    protected void convert(ViewHolder holder, final ReturnGoodsEntity entity, final int position) {

        holder.setText(R.id.tv_cart_good_name, entity.getGoodsName());

        holder.setText(R.id.tv_cart_good_spec, getGoodSpecString(entity.getGoodsSpec(), entity.getUnitName()));

        holder.setText(R.id.tv_goods_count_not_register,
                String.format("退货数量：%s%s", entity.getSelectUnRegisterCount(), entity.getUnitName()));

        holder.setVisible(R.id.tv_goods_count_register, entity.getSelectRegisterCount() > 0);
        holder.setText(R.id.tv_goods_count_register,
                String.format("寄存退货数量：%s%s", entity.getSelectRegisterCount(), entity.getUnitName()));

    }

    private String getGoodSpecString(List<ReturnGoodsEntity.GoodsSpecBean> goodsSpec, String unitName) {
        StringBuilder builder = new StringBuilder();
        builder.append("规格：");
        if (!ListUtil.isListEmpty(goodsSpec) || !TextUtils.isEmpty(unitName)) {
            for (int i = 0; i < goodsSpec.size(); i++) {
                ReturnGoodsEntity.GoodsSpecBean goodsSpecBean = goodsSpec.get(i);
                builder.append(goodsSpecBean.getValue());
                builder.append(",");
            }
            builder.append(unitName);
        } else {
            builder.append("暂无");
        }
        return builder.toString();
    }

}
